﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "IWidget.h"

#include "QDialog"
#include "UIComponent.h"

class QTreeWidget;
class QTreeWidgetItem;

namespace gcmp
{
    class IDock;
}

namespace Ui
{
    class BaseTreeDlg;
}

namespace Sample
{
    // 树形checkbox浮动Dock工具栏
    class UICOMPONENT_EXPORT BaseTreeDlg : public QDialog, public gcmp::IWidget
    {
        Q_OBJECT

    public:
        BaseTreeDlg(QWidget *parent = nullptr);
        ~BaseTreeDlg();

        // 显示Dock
        virtual void ShowDock() = 0;
        // 隐藏Dock
        virtual void HideDock() = 0;
        static gcmp::IDock* GetDock(std::wstring dockId);

        virtual void SetEnabled(bool bEnable) override;
        virtual void UpdateStatus() override {}

        void SetCanCheck(bool flag) { m_canCheck = flag; }
    protected:
        virtual QSize sizeHint() const;
        void keyPressEvent(QKeyEvent *event);
    protected slots:
        virtual void OnTreeItemClicked(QTreeWidgetItem* pItem, int index);

        /// 是否一个节点的子节点都为勾选状态
        bool WhetherChildItemsAllChecked(QTreeWidgetItem* pItem, bool& hasChecked, bool& hasUnChecked);

    protected:
        bool m_canCheck;
        QTreeWidget* m_pQTreeWidget;
    private:
        gcmp::OwnerPtr<Ui::BaseTreeDlg> m_ui;
    };
}

